//build：20240329
//dropdown control
import utils from "./uiUtils.js"
import base from "./uiBase.js"
let dropdown = {}

dropdown.build = function (id, parent) {
    let temp = utils.validateBuild(dropdown.all, id, parent, 'dropdown')
    let my = {type: 'dropdown'}
    my.obj = new utils.GG.NativeDropdown({ uid: id }, temp)
    my.id = id
    /**
     * Set dropdown options content
     * @param {array} arr The options are an array of strings, with each item representing an option.
     */
    my.setOptions = function (arr) {
        this.obj.setOptions(arr.join('\n'))
    }
    /**
     * Get dropdown list
     * @returns The returned list object is a base class object, and its font can be set individually.
     */
    my.getList = function () {
        let res = {}
        res.obj = this.obj.getList()
        return Object.assign(res, base)
    }
    /**
     * This option will be selected by default when setting the selected item.
     * @param {number} index Selected item index
     */
    my.setSelected = function (index) {
        this.obj.setSelected(index)
    }
    /**
     * Get the index of the selected item
     * @returns Returns the currently selected index
     */
    my.getSelected = function () {
        return this.obj.getSelected()
    }
    /**
     * Sets the dropdown menu's accompanying icon; the default is a downward-pointing arrow.
     * @param {string} icon Icon address
     */
    my.setSymbol = function (icon) {
        this.obj.setSymbol(icon)
    }
    let comp = Object.assign(my, base);
    utils.setParent(this.all, comp, parent)
    return comp;
}
export default dropdown;